package com.pb.camera.adapter;

import java.util.ArrayList;
import java.util.List;

import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.pb.camera.HomePageActivity;
import com.pb.camera.application.App;
import com.pb.camera.bean.DeviceMode;
import com.pb.camera.bean.Equipment;
import com.pb.camera.bean.Room;
import com.pb.camera.fragment.HomePageViewPagerFragment;
import com.pb.camera.helper.JsonHelper;

import android.app.Activity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;
import android.widget.Toast;

public class HomePageViewPagerAdapter extends FragmentPagerAdapter {
	/**
	 * 记录tabindicator的数目有多少
	 */
	private List<Room> rooms;
	public List<Room> getRooms() {
		return rooms;
	}

	public void setRooms(List<Room> rooms) {
		this.rooms = rooms;
	}
	private  HttpUtils  httpsUtils;
	private   Activity  activity;
	public HomePageViewPagerAdapter(FragmentManager fm, List<Room> rooms,
			HttpUtils httpsUtils, Activity activity) {
		super(fm);
		this.rooms = rooms;
		this.httpsUtils = httpsUtils;
		this.activity = activity;
	}
	
	public HomePageViewPagerAdapter(FragmentManager fm, List<Room> rooms) {
		super(fm);
		this.rooms = rooms;
		this.httpsUtils=new HttpUtils();
	}
  
	@Override
	public Fragment getItem(int arg0) {
		// TODO Auto-generated method stub
		HomePageViewPagerFragment fragment = new HomePageViewPagerFragment();
		fragment.seCamerasAndRooms(rooms.get(arg0));
		fragment.setPosition(arg0);
		return fragment;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		super.getItemId(position);
		return POSITION_NONE;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if (rooms==null) {
			return 0;
		}
		return rooms.size();
	}
    @Override
    public CharSequence getPageTitle(int position) {
    	// TODO Auto-generated method stub
    	super.getPageTitle(position);
    	if (getCount()==0) {
			return  null;
		}
    	return rooms.get(position).getName();
    }
	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		// TODO Auto-generated method stub
		
		return super.instantiateItem(container, position);

	}
//
//	/**重置rooms
//	 * @param rooms
//	 */
//	public void resetRoomData(List<Room> rooms) {
//		this.rooms = rooms;
//	//	notifyDataSetChanged();
//	}
//
//	/**
//	 * @param homeName
//	 * @param type
//	 *            是房间添加设备了0,还是删除了房间了1,,还是删除了某个房间的设备2
//	 * @param deviceId
//	 */
//	public void roomChange(String homeName, int type, String deviceId) {
//
//	}
//


}
